package com.sky.mapper;

import com.github.pagehelper.Page;
import com.sky.annotation.AutoFill;
import com.sky.dto.DishPageQueryDTO;
import com.sky.entity.Dish;
import com.sky.enumeration.OperationType;
import com.sky.vo.DishVO;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface DishMapper {

    /**
     * 根据分类id查询菜品数量
     * @param categoryId
     * @return
     */
    @Select("select count(id) from dish where category_id = #{categoryId}")
    Integer countByCategoryId(Long categoryId);

    /*
    * 添加菜品数据
    * */
    @AutoFill(value = OperationType.INSERT)
    @Insert("insert into dish (name, category_id,price, image, description,status,create_time,update_time,create_user,update_user)" +
            "values"+"(#{name},#{categoryId},#{price},#{image},#{description},#{status},#{createTime},#{updateTime},#{createUser},#{updateUser})")
    void saveDish(Dish dish);


    /*
    * 菜品分页查询
    * */
    Page<DishVO> pageQuery(DishPageQueryDTO dishPageQueryDTO);

    /*
    * 根据主键查询菜品
    * */
    @Select("select * from dish where id=#{id}")
    Dish getById(Long id);

    /*
    *根据主键id删除菜品数据
    * */
    @Delete("delete from dish where id=#{id}")
    void deleteById(Long id);

    /*
    * 根据ids批量删除菜品数据
    * */
    void deleteBatchByIds(List<Long> ids);

    @AutoFill(OperationType.UPDATE)
    /*
    * 根据传来的dish修改
    * */
    void update(Dish dish);

    /*
    * 根据前端传来的id来修改状态
    * */
    @Update("update dish set status = #{status} where id =#{id} ")
    @AutoFill(OperationType.UPDATE)
    void updateStatus(Long id,Integer status);

    /*
    * 根据id查询status
    * */
    @Select("select status from dish where id = #{id}")
    Integer getStatus(Long id);

    /*
    * 根据分类id查询所属分类菜品
    * */
    @Select("select * from dish where category_id=#{categoryId}")
    List<Dish> getByCategoryId(Long categoryId);
}
